// For authoring Nightwatch tests, see
// http://nightwatchjs.org/guide#usage

//测试左侧导航栏的伸缩
function test_left_sidebar(browser) {
  const nav_btn = 'a.sidebar-toggle';
  browser
    .assert.visible(nav_btn)
    .click(nav_btn)
    .pause(1000)
    .assert.hidden("a.nav-link span")
    .click(nav_btn)
    .pause(1000)
    .assert.visible("a.nav-link span")
}

//测试注销登录
function test_logout(browser) {
  browser
    .assert.hidden('ul.profile-panel')
    .assert.hidden('a.btn-logout')
    .assert.visible('a.profile-panel-toggle')
    .click('a.profile-panel-toggle')
    .pause(500)
    .assert.visible('ul.profile-panel')
    .assert.visible('a.btn-logout')
    .click('a.btn-logout')
    .pause(500)
    .assert.urlContains('login')
}

//测试应用管理

//测试设备管理
function test_devices(browser) {
  const link = 'a.nav-link.nav-devices';
  browser
    .assert.visible(link)
    .click(link)
    .pause(1000)
    .assert.urlContains('devices')
    .assert.visible('section.devices-manage')
}

module.exports = {
  'E2E TEST': function(browser) {
    const devServer = browser.globals.devServerURL;
    const iput_username = 'input#login-email';
    const iput_pwd = 'input#login-password';
    const login_btn = "button#login-btn";
    browser
      .url(devServer)
      .maximizeWindow()
      .waitForElementVisible("div.login-box", 5000, '登录窗口')
      .assert.visible(iput_username, '用户名输入框检查')
      .assert.visible(iput_pwd, '密码输入框检查')
      .assert.visible(login_btn, '登录按钮检查')
      .setValue(iput_username, 'admin')
      .setValue(iput_pwd, "123456")
      .click(login_btn)
      .pause(2000)
//      .assert.title('概览', '登录后标题验证')
      //.assert.urlContains('general', '登陆后URL验证')
      //.assert.visible('a.logo', '登陆后可视元素检查')
      //.assert.visible('ul.sidebar-menu', '登陆后边栏可视检查');

    test_left_sidebar(browser);
    test_devices(browser);
    test_logout(browser);
    browser.end();
  }
}
